package rozetka.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import rozetka.utils.User;

/**
 * Created by foneox on 05.04.2014.
 */
public class LoginDialog extends BasePage {
    private By emailAddressTextFieldLocator = By.name("login");
    private By passwordFieldLocator = By.name("password");
    private By enterButton = By.cssSelector(".button-css-blue.auth-f-submit-btn");

    public LoginDialog(WebDriver driver) {
        super(driver);
    }

    public RegistrationPage followRegistrationPage(){
        driver.findElement(By.cssSelector(".auth-f-signup-link")).click();
        return new RegistrationPage(driver);
    }

    public void loginAs(User user) {
        WebElement emailAddressTextField = driver.findElement(emailAddressTextFieldLocator);
        emailAddressTextField.clear();
        emailAddressTextField.sendKeys(user.getUserEmail());
        WebElement passwordField = driver.findElement(passwordFieldLocator);
        passwordField.clear();
        passwordField.sendKeys(user.getUserPassword());
        driver.findElement(enterButton).click();
    }
}
